package com.dao;


import java.sql.ResultSet;
import java.sql.SQLException;

import com.entity.ProEmp;
import com.util.DBHelp;
import com.util.RowMapper;

public class ProEmpDao {
	
	DBHelp<ProEmp> help=new DBHelp<ProEmp>();

	public void add(ProEmp proEmp) {
		String sql="INSERT INTO t_employee_project(employeeid,projectid,role) VALUES(?,?,?)";
		help.executeSQL(sql, proEmp.getEmployeeid(),proEmp.getProjectid(),proEmp.getRole());
	}
	
	
	
	private class Mapper implements RowMapper<ProEmp>{

		public ProEmp mapperRow(ResultSet rs) throws SQLException {
			ProEmp proEmp=new ProEmp();
			proEmp.setEmployeeid(rs.getString("employeeid"));
			proEmp.setProjectid(rs.getString("projectid"));
			proEmp.setRole(rs.getString("role"));
			
			return proEmp;
		}
		
	}
	
	public void delByProjectId(String id) {
		String sql="DELETE FROM t_employee_project WHERE projectid=?";
		help.executeSQL(sql, id);
	}


	public ProEmp getRole(String eid, String pid) {
		String sql="SELECT `employeeid`,`projectid`,`role` FROM `t_employee_project` WHERE `employeeid`=? AND `projectid`=?";
		return help.executeQueryForObject(sql, new Mapper(), eid,pid);
	}

}
